fix: credential-env reads cred.encryptedKey (not cred.encrypted) - #95
Closed
siglimumuni wants to merge 1 commit into
Closed
fix: credential-env reads cred.encryptedKey (not cred.encrypted)#95siglimumuni wants to merge 1 commit into
siglimumuni wants to merge 1 commit into
Conversation
The execute tool's credential injection has been silently no-op'ing for
all agents: `buildCredentialEnv` read `cred.encrypted` on each Credential
record, but `createCredentialRecord` persists the ciphertext under
`encryptedKey` (confirmed by every other read site — connector-lifecycle,
chatroom-helpers, daemon-state, check-provider). The mismatch fell into
the `Credential has no encrypted value` warn branch on every call,
returning an empty env map. Agents using `executeConfig.credentials` to
inject API tokens into their shell environment never received them.
Concrete impact in our deployment: configured a fine-grained GitHub PAT
as a credential on Hugo + Iris, expecting `gh` inside the agent shell to
authenticate via `GITHUB_TOKEN`. The env var came through as empty, and
`gh` fell back to the host's keychain auth (much broader scope). Switching
the field name to `encryptedKey` makes the injection work as documented.
Confirmed by:
- grep `cred.encrypted` across src/ — this file was the only consumer;
every other site uses `cred.encryptedKey`.
- Live test post-patch: `echo $GITHUB_TOKEN` inside an agent shell now
returns the 93-char fine-grained PAT.
Files:
- src/lib/server/session-tools/credential-env.ts
Member
|
Cherry-picked and shipped in v1.9.33 with maintainer follow-up coverage. Thanks for the fix. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Field-name mismatch in `buildCredentialEnv`. It reads `cred.encrypted` per-credential, but `createCredentialRecord` persists the ciphertext under `cred.encryptedKey`. Every call falls into the `Credential has no encrypted value` warn branch and returns an empty env map.
Result: every agent that uses `executeConfig.credentials` to inject API tokens has been getting an empty env. The execute tool's credential injection is a silent no-op today.
How I found it
Configured a fine-grained GitHub PAT as a credential on a worker agent, expecting `gh` inside its shell to authenticate via `$GITHUB_TOKEN`:
```
echo "GITHUB_TOKEN=${#GITHUB_TOKEN}chars"
→ GITHUB_TOKEN=0chars
```
`gh` then fell back to the host's keychain auth (much broader scope than the fine-grained PAT we tried to scope it to).
Why this is the fix
Every other read site in the codebase already uses `cred.encryptedKey`:
```
$ grep -rn 'cred.encryptedKey\|cred\.encrypted' src/ | grep -v .test.
src/lib/server/session-tools/credential-env.ts: cred.encrypted ← only consumer of the wrong field
src/app/api/setup/check-provider/route.ts: cred.encryptedKey
src/lib/server/connectors/connector-lifecycle.ts: cred.encryptedKey
src/lib/server/chatrooms/chatroom-helpers.ts: cred.encryptedKey
src/lib/server/runtime/daemon-state/core.ts: cred.encryptedKey
```
Verified
After the patch (applied locally to the running build):
```
echo "GITHUB_TOKEN=${#GITHUB_TOKEN}chars; first8=${GITHUB_TOKEN:0:8}"
→ GITHUB_TOKEN=93chars; first8=github_p
gh auth status
→ ✓ Logged in to github.com account siglimumuni (GITHUB_TOKEN)
```
Files
Test plan
🤖 Generated with Claude Code